#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <functional>

void test1()
{
        vector<int> v1;
        v1.push_back(1);
        v1.push_back(2);
        v1.push_back(2);
        v1.push_back(3);
        v1.push_back(5);

        vector<int>::iterator it =  adjacent_find(v1.begin(), v1.end());
        if(it == v1.end()){
                cout<<"没有找到 重复的元素"<<endl;
        }else{
                cout<<*it<<endl;
        }
        int index = distance(v1.begin(), it);
        cout<<"index: "<<index<<endl; 
}

//0 1 2 3 ,....n-1
//二分法1k = 1024 10次就找到了 速度快
void test2()
{
        vector<int> v1;
        v1.push_back(1);
        v1.push_back(3);
        v1.push_back(5);
        v1.push_back(7);
        v1.push_back(9);

        bool b =  binary_search(v1.begin(), v1.end(), 7);       
        if(b == true){
                cout<<"找到了"<<endl;
        }else{
                cout<<"没找到"<<endl;
        }
}

void test3()
{
        vector<int> v1;
        v1.push_back(1);
        v1.push_back(3);
        v1.push_back(5);
        v1.push_back(7);
        v1.push_back(7);
        v1.push_back(9);
        v1.push_back(7);

        int num =  count(v1.begin(), v1.end(), 7);       
        cout<<"num:"<<num<<endl;       
}

bool GreatThree(int num)
{
        if(num > 3){
                return true;
        }
        return false;
}
void test4()
{
        vector<int> v1;
        v1.push_back(1);
        v1.push_back(3);
        v1.push_back(5);
        v1.push_back(7);
        v1.push_back(7);
        v1.push_back(9);
        v1.push_back(7);

        int num = count_if(v1.begin(), v1.end(), GreatThree);
        cout<<"num:"<<num<<endl; 
}

void test5()
{
        vector<int> v1;
        v1.push_back(1);
        v1.push_back(3);
        v1.push_back(5);
        v1.push_back(7);
        v1.push_back(7);
        v1.push_back(9);
        v1.push_back(7);

        vector<int>::iterator it = find(v1.begin(), v1.end(), 5);
        cout<<"it:"<<*it<<endl;  

        //第一个大于3的位置
        it = find_if(v1.begin(), v1.end(),GreatThree);
        cout<<"it:"<<*it<<endl;  
}

int main(int argc, char const *argv[])
{
        //test1();
        //test2();
        //test3();
        //test4();
        test5();
        return 0;
}
